//
//  MainTabBar.swift
//  LJLianXiDaiMa
//
//  Created by 高李军 on 15/8/31.
//  Copyright (c) 2015年 LJLianXi. All rights reserved.
//

import UIKit

class MainTabBar: UITabBar {
    //对里面的五个按钮进行布局
    override func layoutSubviews() {
        super.layoutSubviews()
     //将按钮均分，遍历子视图
        let btnCount = 5;
        let w = self.bounds.size.width / CGFloat(btnCount)
        let h = self.bounds.size.height
        
        //每个按钮大大小固定
        let frame = CGRectMake(0, 0, w , h)
        
        //指定数组中的类型都是UIView,在OC中，所有的控件都继承自UIView
        var index = 0;
        
        for v in subviews as! [UIView]{
            if v is UIControl && !(v is UIButton){
                v.frame = CGRectOffset(frame, CGFloat(index) * w, 0)
                index++
                if index == 2 {
                    index++
                }
            }
        }
        
        self.composedButton.frame = frame;
        self.composedButton.center = CGPointMake(self.center.x, h * 0.5)
        
        
    }
    
    lazy var composedButton:UIButton = {
        let btn = UIButton()
        btn.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        btn.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState:UIControlState.Normal)
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        self.addSubview(btn)
        return btn
    }()
}
